import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {h} from "vue";
import {useUserStore} from "@/store/modules/user";
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '时间',
    align:"center",
    sorter: true,
    dataIndex: 'createTime'
   },
   {
    title: '告警类型',
    align:"center",
    dataIndex: 'type'
   },
  {
    title: '线路',
    align:"center",
    dataIndex: 'lineId_dictText'
  },
  {
    title: '报警终端',
    align:"center",
    dataIndex: 'terminalId_dictText'
  },
  {
    title: '设备编号',
    align:"center",
    dataIndex: 'deviceNo'
  },
  {
    title: '内容',
    align:"center",
    dataIndex: 'alarmMsg'
  },
   {
    title: '是否处理',
    align:"center",
    dataIndex: 'isSolve',
     customRender:({ text }) => {
       // 判断是否显示红球
       if(text === '0'){
         return h('span',{style: {
             color: '#ff0000'
           }},'未处理')
       }else {
         return h('span',{style: {
             color: '#00ff00'
           }},'已处理')
       }
     }
   },
   {
    title: '处理人员',
    align:"center",
    dataIndex: 'updateBy'
   },
   {
    title: '备注',
    align:"center",
    dataIndex: 'remark'
   },
   {
    title: '处理结果',
    align:"center",
    dataIndex: 'solveResult_dictText'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
     {
      label: "创建日期",
      field: "createTime",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
          showTime:true
      },
      //colProps: {span: 6},
	},
	{
      label: "告警类型",
      field: 'type',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "是否处理",
      field: 'isSolve',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "处理人员",
      field: 'solveUserId',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "处理结果",
      field: 'solveResult_dictText',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "终端编号",
      field: 'terminalNo',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "设备编号",
      field: 'deviceNo',
      component: 'Input',
      //colProps: {span: 6},
 	},
];
//表单数据
export const formSchema: FormSchema[] = [

  {
    label: '处理结果',
    field: 'solveResult',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"yc_solve_result"
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择处理结果!'},
      ];
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    dynamicRules: ({model,schema}) => {
      return [
        {required: true, message: '100字数以内的内容!',pattern: /^.{0,100}$/,},
      ];
    },
  },
  {
    field: 'imgString',
    component: 'JImageUpload',
    label: '上传图片',
    helpMessage: '最多上传5张图片',
    componentProps: {
      fileMax : 5,
    }
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  createTime: {title: '创建日期',order: 0,view: 'datetime', type: 'string',},
  type: {title: '告警类型',order: 1,view: 'text', type: 'string',},
  isSolve: {title: '是否处理',order: 2,view: 'text', type: 'string',},
  solveUserId: {title: '处理人员',order: 3,view: 'text', type: 'string',},
  remark: {title: '备注',order: 4,view: 'text', type: 'string',},
  solveResult: {title: '处理结果',order: 5,view: 'text', type: 'string',},
  img: {title: '现场图片',order: 6,view: 'image', type: 'string',},
  terminalNo: {title: '终端编号',order: 7,view: 'text', type: 'string',},
  deviceNo: {title: '设备编号',order: 8,view: 'text', type: 'string',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
